/**
 * 
 */
package com.util;

import java.util.Map;

import com.action.IAction;
import com.action.LoginAction;
import com.cms.action.DownloadAction;
import com.cms.action.MessageAction;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;



/**
 * @author jun.huang
 * 
 */
public class AuthorizeInterceptor extends AbstractInterceptor {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * @param args
	 */
	public static void main(String[] args) {

	}

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		
		//获取session
		Map session=invocation.getInvocationContext().getSession(); 
		//获取拦截器对象
		Object action = (Action) invocation.getAction();
		//如果获取的拦截器为 AdminLoginAction或者UserLoginAction,则不进行拦截
		if(action instanceof LoginAction || action instanceof IAction || action instanceof MessageAction || action instanceof DownloadAction){
			return invocation.invoke();
		}
		//得到session中的用户
		//如果用户为空则跳到LOGIN页面，否则退出拦截
		if(session.get(ConstantUtil.ACCOUNTSESSIONNAME)==null){
			return Action.LOGIN;
		}else{
			return invocation.invoke();
		}
		//return invocation.invoke();
	}

}
